package com.lzy.concertticket.model;

import lombok.Data;

import java.util.HashMap;

public class R extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    public static final String CODE_TAG = "code";
    public static final String MSG_TAG = "msg";
    public static final String DATA_TAG = "data";

    public static final int SUCCESS = 200;

    public static final int FAIL = 500;

    public R() {
        put(CODE_TAG, SUCCESS);
        put(MSG_TAG, "操作成功");
        put(DATA_TAG, null);
    }

    public R(Object data) {
        put(CODE_TAG, SUCCESS);
        put(MSG_TAG, "操作成功");
        put(DATA_TAG, data);
    }

    public R(int code, String msg) {
        put(CODE_TAG, code);
        put(MSG_TAG, msg);
        put(DATA_TAG, null);
    }

    public R(int code, String msg, Object data) {
        put(CODE_TAG, code);
        put(MSG_TAG, msg);
        put(DATA_TAG, data);
    }


    public static R success() {

        return new R(SUCCESS, "操作成功", null);
    }

    public static R success(Object data) {

        return new R(SUCCESS, "操作成功", data);
    }

    public static R fail() {

        return new R(FAIL, "操作失败", null);
    }

    public static R fail(String msg) {

        return new R(FAIL, msg);
    }

    public static R fail(String msg, Object data) {

        return new R(FAIL, msg, data);
    }

    public static R fail(Integer code, String msg) {

        return new R(code, msg);
    }

    public static R fail(Integer code, String msg, Object data) {

        return new R(code, msg, data);
    }

}
